package com.ansion.utils;

import android.text.TextUtils;

import androidx.annotation.Nullable;

import com.ansion.log.VLog;
import com.ansion.preference.TurboBasePreference;

/**
 * bot相关业务用.
 * <p>
 * 注意: 一定要在用户登录成功后使用.
 */
public class BotPreferenceUtils extends TurboBasePreference {

    private static final String FIRST_EVENT_CALL_TIME = "first_event_call_time";
    private static final String FIRST_EVENT_MESSAGE_TIME = "first_event_message_time";
    private static final String USER_PROFILE_EXTRA_INFO = "user_profile_extra_info";

    private static BotPreferenceUtils mInstance;

    protected BotPreferenceUtils(String name) {
        super(name);
    }

    @Nullable
    public static BotPreferenceUtils getInstance() {
        if (mInstance == null) {
            synchronized (BotPreferenceUtils.class) {
                if (mInstance == null) {
                    String loginUcId = "123456";
                    if (TextUtils.isEmpty(loginUcId)) {
                        return null;
                    }
                    mInstance = new BotPreferenceUtils("botim_user_storage" + loginUcId);
                }
            }
        }

        return mInstance;
    }

    public long getFirstEventMessageTime() {
        return getLong(FIRST_EVENT_MESSAGE_TIME, 0);
    }

    public void setFirstEventMessageTime(long time) {
        putLong(FIRST_EVENT_MESSAGE_TIME, time);
    }

    public long getFirstEventCallTime() {
        return getLong(FIRST_EVENT_CALL_TIME, 0);
    }

    public void setFirstEventCallTime(long time) {
        putLong(FIRST_EVENT_CALL_TIME, time);
    }

    public void setUserProfileExtraInfo(String extraInfo) {
        VLog.i("TAG_ASKUSERMANAGER", "save userExtra:%s", extraInfo);
        putString(USER_PROFILE_EXTRA_INFO, extraInfo);
    }

    public String getUserProfileExtraInfo() {
        return getString(USER_PROFILE_EXTRA_INFO, "");
    }

    @Override
    public void logout() {
    }

    /**
     * 重置单例，以便当前登录用户正确使用
     */
    public static void reset() {
        mInstance = null;
    }
}
